package com.chengshi.shop.service.shop.impl;

import com.chengshi.shop.dao.system.ShopConfigMapper;
import com.chengshi.shop.model.system.ShopConfig;
import com.chengshi.shop.service.shop.ShopService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 商城配置
 *
 * @author xuxinlong
 * @version 2017年09月30日
 */
@Service
public class ShopServiceImpl implements ShopService {
    @Resource
    private ShopConfigMapper shopConfigMapper;


    /**
     * 获取商家配置
     *
     * @param key
     * @return
     */
    @Override
    public String getShopConfig(String key) {
        return shopConfigMapper.getConfig(key);
    }

    /**
     * 保存商家配置
     *
     * @param key
     * @param shopIntro
     */
    @Override
    public void saveShopConfig(String key, String shopIntro) {
        ShopConfig shopConfig = shopConfigMapper.findByKey(key);
        if (shopConfig != null) {
            shopConfig.setValue(shopIntro);
            shopConfigMapper.saveConfig(key, shopIntro);
        } else {
            shopConfig = new ShopConfig();
            shopConfig.setKey(key);
            shopConfig.setValue(shopIntro);
            shopConfig.setCreateTime(new Date());
            shopConfigMapper.insertSelective(shopConfig);
        }
    }

    /**
     * 获取商城配置列表
     *
     * @return
     */
    @Override
    public List<ShopConfig> getShopConfigList() {
        return shopConfigMapper.getList();
    }
}
